

function say() {
    alert("LC:435. 无重叠区间");
}
say();


/**
 * @param {number[][]} intervals
 * @return {number}
 */
var eraseOverlapIntervals = function(intervals) {
    //10:26-41
    if(intervals.length == 0){
        return 0
    }
    bubleSort(intervals)

    var count = 0
    var end = intervals[0][1]

    for(var i = 1; i < intervals.length; i++){
        var item = intervals[i]
        if(item[0] < end){ //有交叉
            end = Math.min(end, item[1]) //保留最小的end,小区间,交叉的概率小
            count++
        }else {
            end = item[1]
        }
    }
    return count
};

function bubleSort(arr){
    for(var i = 0; i < arr.length; i++){
        for(var j = 0; j < arr.length - 1 - i; j++){
            if(arr[j][0] > arr[j + 1][0]){
                var temp = arr[j]
                arr[j] = arr[j + 1]
                arr[j + 1] = temp
            }
        }
    }
}
